#include <iostream>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int nearest_prime(int n) {
    int lower_prime = -1;
    int upper_prime = -1;
    for (int i = n - 1; i > 1; --i) {
        if (is_prime(i)) {
            lower_prime = i;
            break;
        }
    }
    for (int i = n + 1; i < n * 2; ++i) {
        if (is_prime(i)) {
            upper_prime = i;
            break;
        }
    }
    if (lower_prime != -1 && upper_prime != -1) {
        if (n - lower_prime <= upper_prime - n) {
            return lower_prime;
        } else {
            return upper_prime;
        }
    } else if (lower_prime != -1) {
        return lower_prime;
    } else if (upper_prime != -1) {
        return upper_prime;
    } else {
        return -1;
    }
}

int word_to_number(std::string word) {
    std::unordered_map<std::string, int> number_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    auto it = number_dict.find(word);
    if (it != number_dict.end()) {
        return it->second;
    }
    return -1;
}

void main_func(std::string input_text) {
    std::vector<std::string> words;
    std::string word;
    for (char c : input_text) {
        if (c == ' ') {
            words.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    words.push_back(word); // Добавляем последнее слово

    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return;
    }

    int number = 0;
    for (std::string word : words) {
        int num = word_to_number(word);
        if (num == -1) {
            std::cout << "Wrong input" << std::endl;
            return;
        }
        number = number * 10 + num;
    }

    if (100 <= number && number <= 999) {
        int prime = nearest_prime(number);
        std::cout << prime << std::endl;
    } else {
        std::cout << "Wrong input" << std::endl;
    }
}

int main() {
    std::string input_text;
    std::getline(std::cin, input_text);
    main_func(input_text);

    return 0;
}